package cn.school.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    private DateUtil() {
    }

    final static SimpleDateFormat DF = new SimpleDateFormat("yyyy-MM-dd");

    public static String toString(Date d) {
        if (d == null)
            return "";
        return DF.format(d);
    }

    public static Date toDate(String d) {
        if (d == null)
            return null;
        try {
            return DF.parse(d);
        } catch (ParseException e) {
            //e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        String s = "2020-4-1";
        System.out.println(toDate(s));
    }
}
